#include "RenderObjectHandler.hpp"
#include "RenderObject.hpp"

namespace rgui
{

RenderObjectHandler::RenderObjects RenderObjectHandler::renderObjects;

void RenderObjectHandler::add(rgui::RenderObject *renderObject)
{
	renderObjects.push_back(renderObject);
}

void RenderObjectHandler::remove(rgui::RenderObject *renderObject)
{
	for(RenderObjects::iterator it = renderObjects.begin(); it != renderObjects.end(); ++it)
	{
		if(renderObject == *it)
		{
			renderObjects.erase(it);
			break;
		}
	}
}

void RenderObjectHandler::onMousePressed(const rgui::vec2i &cursorPosition)
{
	for(RenderObjects::iterator it = renderObjects.begin(); it != renderObjects.end(); ++it)
	{
		(*it)->onMousePressed(cursorPosition);
	}
}

void RenderObjectHandler::onMouseReleased(const rgui::vec2i &cursorPosition)
{
	for(RenderObjects::iterator it = renderObjects.begin(); it != renderObjects.end(); ++it)
	{
		(*it)->onMouseReleased(cursorPosition);
	}
}

void RenderObjectHandler::update(const rgui::vec2i &cursorPosition)
{
	for(RenderObjects::iterator it = renderObjects.begin(); it != renderObjects.end(); ++it)
	{
		(*it)->update(cursorPosition);
	}
}

void RenderObjectHandler::render()
{
	for(RenderObjects::iterator it = renderObjects.begin(); it != renderObjects.end(); ++it)
	{
		if((*it)->isVisible())
			(*it)->render();
	}
}

}